<template>
	<view class="resume-container">
		<view class="resume-head" :style="{ paddingTop: barHeight + 20 + 'rpx' }">
			<image src="@/static/img/arr.png" mode="" @click="goto"></image>
			<text class="title">我的求职</text>
		</view>
		<view class="resume-main">
			<view class="main-info"  v-if="data.userInfo?.appUserAuthentication?.name">
				<view class="info-top">
					<view class="top-left">
						<view class="name">
							<view class="name-user">	{{ data.userInfo?.appUserAuthentication?.name }}</view>
							 
						</view>
						<view class="user">{{ data.userInfo?.appUserAuthentication?.gender.name }} | {{ data.userInfo?.age }}</view>
					</view>
					<image v-if="data.userInfo?.appUserResume?.avatarFileId" :src="httpUrl+'/app/file/viewFile?fileId='+ data.userInfo?.appUserResume.avatarFileId" ></image>
					<image  v-else src="@/static/img/common/user.jpg" mode="" ></image>
				</view>
				<view class="phones">
					<image src="@/static/img/common/phone.png" mode=""></image>
					<view class="num">{{ maskPhoneNumber(data.userInfo?.phone)  }}</view>
				</view>
				<view class="pickers mg-tp15">
					<view class="pcikers-title">学历: </view>
					<picker style="width: 100%;height: 40rpx;" :value="pickers.selectIndex" mode="selector" range-key="name" :range="pickers.range" @change="bindPickerChange">
						<view class="pickerss" >{{  pickers.range && pickers.range[pickers.selectIndex] ? setXl(pickers.range[pickers.selectIndex].value) : '请选择学历'}} <image src="/static/img/common/edi.png" mode="" @click="jump(1)"></image></view>
					</picker>
				</view>
       
			</view>
			<view class="main-info" v-if="!data.userInfo?.appUserAuthentication?.name">
				<view class="info-top">
					<view class="top-left">
						<view class="name">
							<view class="name-user"><image src="/static/img/common/edi.png" mode="" @click="jump(1)"></image></view>
						</view>
						<view class="">暂无数据</view>
					</view>
				</view>
			</view>
			<view class="main-qw" v-if="data.userInfo?.appUserDesire?.length">
				<view class="qw-top">
					<view class="top-title">求职期望</view>
					<image src="/static/img/common/edi.png" mode="" @click="jump(2)"></image>
				</view>
				<view class="qw-middle">
					<view class="middle-left">
						<view class="left-title">
							<text>{{ data.userInfo.appUserDesire[0].positionName }}</text>
					  	<text class="money" v-if="data.userInfo?.appUserDesire[0].salaryMin !== null && data.userInfo?.appUserDesire[0].salaryMax !== null">{{ convertToK(data.userInfo.appUserDesire[0].salaryMin) }} - {{ convertToK(data.userInfo.appUserDesire[0].salaryMax) }}</text>
							<text class="money" v-if="data.userInfo?.appUserDesire[0].salaryMin === null || data.userInfo?.appUserDesire[0].salaryMax === null" >面议</text>
						</view>
						<view class="left-boder">
							<!-- <view class="border-item">{{ setName(data.userInfo.appUserDesire[0].expectWorkType) }}</view> -->
							<view class="border-item">{{ setName1(data.userInfo?.appUserDesire[0]?.positionType) }}</view>
						</view>
						<view class="desc-time">工作时间: {{ data.userInfo?.appUserDesire[0].workTime }}</view>
					</view>
					<!-- <image src="/static/img/common/arrr.png" mode=""></image> -->
				</view>
				<view class="qw-bt">
					<view class="bt-zw">{{ setName(data.userInfo?.appUserDesire[0]?.expectWorkType) }}</view>
					<view class="bt-dz">{{ data.userInfo?.appUserDesire[0]?.workProvinceName }} {{data.userInfo?.appUserDesire[0]?.workCityName}} {{ data.userInfo?.appUserDesire[0]?.workDistrictName }}</view>
				</view>
			</view>
			<view class="main-qw" v-if="!data.userInfo?.appUserDesire?.length">
				<view class="qw-top">
					<view class="top-title">求职期望</view>
					<image src="/static/img/common/edi.png" mode="" @click="jump(2)"></image>
				</view>
				<view class="mg-tp20">暂无数据</view>
			</view>

			<view class="main-tc" v-if="data.userInfo?.appUserResume?.introduction">
				<view class="tc-top">
					<view class="top-title">技能/特长</view>
					<image src="/static/img/common/edi.png" mode="" @click="jump(4)"></image>
				</view>
				<view class="tc-desc">{{ data.userInfo?.appUserResume?.introduction }}</view>
			</view>	
			<view class="main-tc" v-if="!data.userInfo?.appUserResume?.introduction">
				<view class="tc-top">
					<view class="top-title">技能/特长</view>
					<image src="/static/img/common/edi.png" mode="" @click="jump(4)"></image>
				</view>
				<view class="mg-tp20">暂无数据</view>
			</view>
			<!-- 工作经历 -->
			<view class="main-jl" v-if="data.userInfo?.appUserWorkExperience?.length">
				<view class="jl-top">
					<view class="jl-title">工作经历</view>
					<image src="/static/img/common/adddd.png" mode="" @click="jump(5)"></image>
				</view>
				<view class="jl-content">
					<view class="content-item"
					 v-for="(item, index) in data.userInfo?.appUserWorkExperience"
					 @click="jump(6, item)">
						<view class="item-top">
							<view class="top-name">{{ item.companyName }}</view>
							<view class="top-time">{{ item.inTimeStart }} - {{ item.inTimeEnd }}</view>
						</view>
						<view class="item-desc">
							<view class="desc-text">{{ item.workDesc }}</view>
							<uni-icons type="right"></uni-icons>
						</view>
					</view>
				</view>
			</view>
			<view class="main-jl" v-if="!data.userInfo?.appUserWorkExperience?.length">
				<view class="jl-top">
					<view class="jl-title">工作经历</view>
					<image src="/static/img/common/adddd.png" mode="" @click="jump(5)"></image>
				</view>
				<view class="mg-tp20">暂无数据</view>
			</view>
		</view>
		<view class="main-yc">
			<switch style="transform:scale(0.7)" :checked="isChecked" @change="changeSw" />
		</view>
		
	</view>
</template>

<script setup>
import { ref, reactive, onMounted } from "vue"
import { onLoad } from '@dcloudio/uni-app'
import commonNavBar from "@/components/commonNavBar.vue";
import scrollView from "@/components/scrollView.vue";
import { getStatusBarHeight } from '@/utils/common/common.js'
import api from '@/utils/api/recruit.js'
import { getUserImInfo } from '@/utils/api/userInfo.ts'
import { TUILogin } from '@tencentcloud/tui-core';
import { showToast } from "../../utils/toast";
const barHeight = ref(null)		
import { convertToK } from '@/utils/common/common.js'
onLoad(_ => {
	barHeight.value = getStatusBarHeight()
	// const res = TUILogin.getContext();
	// console.log(getUserImInfo(), '=res');
	uni.$on('refsh', _ => {
		// 刷新简历
		getDetail()
	})
})
onMounted(_ => {
	getDetail()
})
const edRef = ref(null)
const pickers = ref({
	range: [
		{name: '小学', value: 'PRIMARY_SCHOOL'}, {name: '初中', value: 'JUNIOR_HIGH_SCHOOL'},
		{name: '高中/中专/技校', value: 'HIGH_SCHOOL'}, {name: '大专', value: 'JUNIOR_COLLEGE'},
		{name: '本科', value: 'UNDERGRADUATE'}, {name: '研究生', value: 'GRADUATE_STUDENT'},
		{name: '博士', value: 'DOCTOR'}, {name: '教授/专家', value: 'PROFESSOR'},
		] , selectIndex: '' }
)
const httpUrl = getApp().globalData.baseUrl
const data = reactive({
	userInfo: {

	}
})
// 学历选择
const bindPickerChange = async e => {
	let index = e.detail.value
	pickers.value.selectIndex = index
	let edValue = pickers.value.range[index].value
	// form.formData.education = pickers.range[index].value
	let data = {
		saveType: 'PERSONAL_DATA',
		appUserResume: {
			education: edValue
		}
	}
	const res = await api.saveUserResume(data)
	if(res.code === 200) {
		showToast(res.msg)
		getDetail()
	}
}
const isChecked = ref(false)
const getDetail = async _ => {
	const res = await api.viewResume()
	data.userInfo = res.data
	isChecked.value = data.userInfo?.appUserResume?.resumeState === 'SHOW' ? true : false
	if(data.userInfo.appUserResume?.education){
		let ed = data.userInfo.appUserResume?.education
		let xlIndex = pickers.value.range.findIndex(item=>item.value == ed)
		pickers.value.selectIndex = xlIndex
	}
}
// 显示/隐藏简历
const changeSw = async(e) => {
	isChecked.value = false
	const res = await api.setUserResume({ resumeId: data.userInfo.appUserResume.id })
	console.log(res);
	if(res.code === 200) {
		showToast(res.msg)
		getDetail()
	} else {
		console.log(111212);
	}

}
const  maskPhoneNumber = (phoneNumber) => {
  // 确保输入是一个有效的手机号
  if (!/^\d{11}$/.test(phoneNumber)) {
    console.log('请输入有效的手机号');
    return;
  }

  // 将手机号转成数组并替换中间的几位为 '*'
  const masked = phoneNumber.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
  
  return masked;
}
const setName = (positionName) => {
	// 根据 positionName 返回不同的文字
	switch (positionName) {
		case 'FULL_TIME':
			return '全职';
		case 'PART_TIME_JOB':
			return '兼职';
		default:
			return '未知';
	}
}
const setName1 = (positionName) => {
	// 根据 positionName 返回不同的文字
	switch (positionName) {
		case 'OFFLINE':
			return '线下';
		case 'ONLINE':
			return '线上';
		default:
			return '未知';
	}
}
const setXl = (positionName) => {
	// 根据 positionName 返回不同的文字
	switch (positionName) {
		case 'NONE':
			return '不限';
		case 'PRIMARY_SCHOOL':
			return '小学';
		case 'JUNIOR_HIGH_SCHOOL':
			return '初中';
		case 'HIGH_SCHOOL':
			return '高中/中专/技校';
		case 'JUNIOR_COLLEGE':
			return '大专';
		case 'UNDERGRADUATE':
			return '本科';
		case 'GRADUATE_STUDENT':
			return '研究生';
		case 'DOCTOR':
			return '博士';
		case 'PROFESSOR':
			return '教授/专家';
		default:
			return '未知';
	}
}
// 编辑操作
const jump = (index, item) => {
	if(index === 1) {
		// xl()
		// if(data.userInfo.appUserResume?.education){
		// 	let ed = data.userInfo.appUserResume?.education
		// 	let xlIndex = pickers.value.range.findIndex(item=>item.value == ed)
		// 	pickers.value.selectIndex = xlIndex
		// }
		// edRef.value.open('center')
		// let datas = data.userInfo.appUserAuthentication?.avatarFileId ? data.userInfo.appUserAuthentication : {}
		// datas.birthday = data.userInfo.appUserAuthentication.birthday
		// datas.sex = data.userInfo.appUserAuthentication.gender.value
		// datas.linkPhone = data.userInfo.phone
		// datas.name = data.userInfo.appUserAuthentication.name ? data.userInfo.appUserAuthentication.name : ''
		// uni.navigateTo({ url: `/pages/resume/personal?data=${JSON.stringify(datas)}` })
	} else if(index === 2){
		let datas = data.userInfo.appUserDesire?.length ? data.userInfo.appUserDesire : []
		uni.navigateTo({ url: `/pages/resume/jobExpectation?data=${JSON.stringify(datas)}` })
	} else if(index === 3) {
		uni.navigateTo({ url: '/pages/resume/jobRequirement' })
	} else if(index === 4) {
		let str = data.userInfo.appUserResume?.introduction ? data.userInfo.appUserResume?.introduction :''
		uni.navigateTo({ url: '/pages/resume/skillStrengths?strs=' + str })
	} else if(index === 5){
		uni.navigateTo({ url: `/pages/resume/workExperience` })
	} else {
		let datas = { type: 'edit', ...item}
		uni.navigateTo({ url: `/pages/resume/workExperience?data=${JSON.stringify(datas)}` })
	}
}
// 返回
const goto = _ => uni.navigateBack()
</script>

<style lang="scss">
.pickers{
	display: flex;
	align-items: center;
	.pcikers-title{
		width: 100rpx;
		height: 40rpx;
		font-weight: normal;
		font-size: 28rpx;
		color: #262626;
	}
	.pickerss{
		display: flex;
		align-items: center;
		image{
			width: 48rpx;
			height: 48rpx;
			margin-left: 12rpx;
		}
	}
}
.resume-container{
	width: 100%;
	height: 100vh;
	background: #fff;
	.resume-head{
		width: 100%;
		display: flex;
		align-items: center;
		// justify-content: space-between;
		width: 750rpx;
		height: 98rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		padding-left:32rpx;
		padding-right: 32rpx;
		box-sizing: border-box;
		image{
			width: 36rpx;
			height: 36rpx;
		}
		.title{
			width: 100%;
			flex: 1;
			font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
			font-weight: normal;
			font-size: 32rpx;
			color: #333333;
			// line-height: 48rpx;
			// text-align: center;
			font-style: normal;
			text-transform: none;
			margin-left: 269rpx;

		}
	}
	.resume-main{
		padding: 24rpx 32rpx;
		box-sizing: border-box;
		.main-info{
			padding-bottom: 32rpx;
			box-sizing: border-box;
			width: 100%;
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			border-bottom: 1rpx solid #F4F6FA;
			.info-top{
				display: flex;
				align-items: center;
				justify-content: space-between;
				.top-left{
					.name{
						display: flex;
						align-items: center;
						.name-user{
							font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
							font-weight: normal;
							font-size: 48rpx;
							color: #000000;
							line-height: 72rpx;
							text-align: left;
							font-style: normal;
							text-transform: none;

						}
						image{
							width: 42rpx;
							height: 42rpx;
							margin-left: 12rpx;
						}
					}
					.user{
						font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
						font-weight: normal;
						font-size: 32rpx;
						color: #595959;
						line-height: 48rpx;
						// text-align: center;
						font-style: normal;
						text-transform: none;
						margin-top: 16rpx;
					}
				}
				image{
					width: 128rpx;
					height: 128rpx;
					border-radius: 50%;
				}
			}
			.phones{
				display: flex;
				align-items: center;
				margin-top: 19rpx;
				font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
				font-weight: normal;
				font-size: 32rpx;
				color: #595959;
				line-height: 48rpx;
				text-align: center;
				font-style: normal;
				text-transform: none;
				
				image{
					width: 42rpx;
					height: 42rpx;
					margin-right: 12rpx;
				}
			}
		}
		.main-qw{
			padding: 32rpx 0;
			box-sizing: border-box;
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			border-bottom: 1rpx solid #F4F6FA;
			.qw-top{
				display: flex;
				align-items: center;
				justify-content: space-between;
				.top-title{
					font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
					font-weight: bold;
					font-size: 36rpx;
					color: #000000;
					line-height: 54rpx;
					text-align: left;
					font-style: normal;
					text-transform: none;
				}
				image{
					width: 48rpx;
					height: 48rpx;
				}
			}
			.qw-middle{
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 16rpx;
				.middle-left{
					width: 100%;
					.left-title{
						width: 100%;
						display: flex;
						align-items: center;
						justify-content: space-between;
						.name{
							font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
							font-weight: normal;
							font-size: 32rpx;
							color: #262626;
							line-height: 48rpx;
							text-align: left;
							font-style: normal;
							text-transform: none;
						}
						.money{
							font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
							font-weight: normal;
							font-size: 36rpx;
							color: #6B64D3;
							line-height: 54rpx;
							text-align: left;
							font-style: normal;
							text-transform: none;
						}
					}
					.desc-time{
						font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
						font-weight: normal;
						font-size: 32rpx;
						color: #595959;
						line-height: 48rpx;
						text-align: left;
						font-style: normal;
						text-transform: none;
						margin-top: 12rpx;
					}
					.left-boder{
						margin-top: 12rpx; 
						display: flex;
						align-items: center;
						.border-item{
							padding: 6rpx 12rpx;
							box-sizing: border-box;
							font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
							font-weight: normal;
							font-size: 24rpx;
							color: #8C8C8C;
							line-height: 36rpx;
							text-align: left;
							font-style: normal;
							text-transform: none;
							margin-right: 10rpx;
							background: #F4F6FA;
							border-radius: 8rpx 8rpx 8rpx 8rpx;
						}
					}
				}
				image{
					width: 48rpx;
					height: 48rpx;
				}
			}
			.qw-bt{
				margin-top: 12rpx;
				display: flex;
				align-items: center;
				.bt-zw{
					font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
					font-weight: normal;
					font-size: 32rpx;
					color: #595959;
					line-height: 48rpx;
					text-align: left;
					font-style: normal;
					text-transform: none;
				}
				.bt-dz{
					font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
					font-weight: normal;
					font-size: 32rpx;
					color: #595959;
					line-height: 48rpx;
					text-align: left;
					font-style: normal;
					text-transform: none;
					margin-left: 20rpx;
				}
			}
		}
		.main-yq{
			padding: 32rpx 0;
			box-sizing: border-box;
			border-bottom: 1rpx solid #F4F6FA;
			.yq-top{
				display: flex;
				align-items: center;
				justify-content: space-between;
				.top-title{
					font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
					font-weight: bold;
					font-size: 36rpx;
					color: #000000;
					line-height: 54rpx;
					text-align: left;
					font-style: normal;
					text-transform: none;
				}
				image{
					width: 48rpx;
					height: 48rpx;
				}
			}
			.yq-desc{
				margin-top: 16rpx;
				.desc-time{
					font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
					font-weight: normal;
					font-size: 32rpx;
					color: #595959;
					line-height: 48rpx;
					text-align: left;
					font-style: normal;
					text-transform: none;
				}
				.desc-qy{
					font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
					font-weight: normal;
					font-size: 32rpx;
					color: #595959;
					line-height: 48rpx;
					text-align: left;
					font-style: normal;
					text-transform: none;
				}
			}
		}
		.main-tc{
			padding: 32rpx 0;
			box-sizing: border-box;
			border-bottom: 1rpx solid #F4F6FA;
			.tc-top{
				display: flex;
				align-items: center;
				justify-content: space-between;
				.top-title{
					font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
					font-weight: bold;
					font-size: 36rpx;
					color: #000000;
					line-height: 54rpx;
					text-align: left;
					font-style: normal;
					text-transform: none;
				}
				image{
					width: 48rpx;
					height: 48rpx;
				}
			}
			.tc-desc{
				margin-top: 16rpx;
				font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
				font-weight: normal;
				font-size: 32rpx;
				color: #595959;
				line-height: 48rpx;
				text-align: left;
				font-style: normal;
				text-transform: none;

			}
		}
		.main-jl{
			padding: 32rpx 0;
			box-sizing: border-box;
			// border-bottom: 1rpx solid #F4F6FA;
			.jl-top{
				display: flex;
				align-items: center;
				justify-content: space-between;
				.jl-title{
					font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
					font-weight: bold;
					font-size: 36rpx;
					color: #000000;
					line-height: 54rpx;
					text-align: left;
					font-style: normal;
					text-transform: none;
				}
				image{
					width: 48rpx;
					height: 48rpx;
				}
			}
			.jl-content{
				margin-top: 8rpx;
				.content-item{
					padding-bottom: 32rpx;
					border-bottom: 1rpx solid #F4F6FA;
					.item-top{
						display: flex;
						align-items: center;
						justify-content: space-between;
						margin-top: 16rpx;
						.top-name{
							font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
							font-weight: normal;
							font-size: 28rpx;
							color: #8C8C8C;
							line-height: 42rpx;
							text-align: left;
							font-style: normal;
							text-transform: none;
						}
						.top-time{
							font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
							font-weight: normal;
							font-size: 28rpx;
							color: #8C8C8C;
							line-height: 42rpx;
							text-align: left;
							font-style: normal;
							text-transform: none;
						}
					}
					.item-desc{
						width: 100%;
						display: flex;
						align-items: center;
						justify-content: space-between;
						margin-top: 16rpx;
						
						.desc-text{
							font-family: Alibaba PuHuiTi 2.0, Alibaba PuHuiTi 20;
							font-weight: normal;
							font-size: 32rpx;
							color: #595959;
							line-height: 48rpx;
							text-align: left;
							font-style: normal;
							text-transform: none;
							width: 99%;
						}
					}
				}
			}
		}

	}
	.main-yc{
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
	}
}
::v-deep .uni-switch-input{
	width: 300rpx;
	height: 60rpx;
}
::v-deep .uni-switch-input:after{
	transform: translateX(240rpx);
}
::v-deep .uni-switch-input:before{
	width: 300rpx;
}
::v-deep .uni-switch-input.uni-switch-input-checked:after{
	transform: translateX(0rpx);
}
</style>
